const nunjucks = require('nunjucks');
const path = require('path');
const fs = require('fs');
const jsonplus = require('jsonplus');
let process = require('process')

const { execFile, exec } = require('child_process');

nunjucks.configure(path.join(__dirname, '/templates'), { autoescape: true });

function generator(json) {
    let result = nunjucks.render('test.njk', json)
    const page_path = './app/src/index.js';
    wlos_write(page_path, result);
}

function wlos_write(path, json) {
    fs.writeFile(path, json, function (err) {
        if (err) {
            console.log(`${path} 写入失败`, err);
        } else {
            console.log(`${path} 写入成功`);
        }
    });
}

generator(jsonplus.parse(fs.readFileSync('./data/ui.json', 'utf8')));